/******************** 
	作用:参数设置
	作者:fei
	版本:V1.0
	时间:2015-07-27
********************/

$(function() {
	var tableId = "#dynamic-table"; //表格ID
	var editUrl="/Settings/Parameter/add";//设置1提交的地址
	var batUrl=editUrl;//批量设置提交的地址  注：type:6
	
	//
	General.initCheckbox(); //初始化表格中的复选框事件监听
	General.extendDialog(); //扩展对话框
	//批量修改：
	$("#batSet").click(function(){
		var setGruop1=$("#setGruop1").prop("checked");
		var setGruop1_title=$("#setGruop1_title").val();
		var setGruop2=$("#setGruop2").prop("checked");
		var setGruop2_title=$("#setGruop2_title").val();
		var setGruop3=$("#setGruop3").prop("checked");
		var setGruop3_title=$("#setGruop3_title").val();
		var setGruop4=$("#setGruop4").prop("checked");
		var setGruop4_title=$("#setGruop4_title").val();
		var setGruop5=$("#setGruop5").prop("checked");
		var setGruop5_title=$("#setGruop5_title").val();
		
		var url=batUrl;
		var data={data:{
				"type": 6,
				'setGruop1':setGruop1,
				'setGruop1_title':setGruop1_title,
				'setGruop2':setGruop2,
				'setGruop2_title':setGruop2_title,
				'setGruop3':setGruop3,
				'setGruop3_title':setGruop3_title,
				'setGruop4':setGruop4,
				'setGruop4_title':setGruop4_title,
				'setGruop5':setGruop5,
				'setGruop5_title':setGruop5_title
			}
		}
		console.log(data);
		if(url!=''){
			Common.ajaxPostWantResult(url,data,'批量修改',window);
		}
		//
		//
	});
	//设置点击一组单选按钮，显示或隐藏别一个div
	function radioShowHideDiv($container,name){
		var $target=$container.find("input[name='"+name+"']");
		$target.click(function(){
			var findId=$(this).attr('data-showhideId');
			var str='#'+findId;
			var $div=$container.find(str);
			var isSelect=$container.find("input[name='"+name+"']:checked").val();
			if(isSelect==1){
				$div.removeClass('hide');
			}else{
				$div.addClass('hide');
			}
			//
		});
	}
	//---------------------------编辑备注
	//点击行内"设置"按钮
	$(tableId + ">tbody a[data-id=edit]:not([disabled])").on("click", function(e) {
		var tr=$(this).closest("tr");
		var id = parseInt(tr.attr("data-id")); //获取id
		//console.log("id:"+id);
		var allow1;
		var allow2;
		var $allow1Value;
		var allow2SubSelectIndex=-1;
		var $allow2Value;
		//设置值
		var $dialog_edit=$("#dialog-edit");
		var divName="#tpl-remark"+id;
		var strHtml=$(divName).html();
		$dialog_edit.html(strHtml);
		//设置标题
		var arrTitle=['积分','佣金','余额','红包','优惠券'];
		var title="设置："+arrTitle[id<=0?0:id-1];
		//
		$("#dialog-edit").removeClass('hide').dialog({
			resizable: false,
			width: '810',
			modal: true,
			title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-edit green'></i>"+title+"</h4></div>",
			title_html: true,
			buttons: [{
				html: "<i class='ace-icon fa fa-save'></i> 确定",
				"class": "btn btn-info btn-minier btn-space-right",
				click: function() {
					var url = editUrl;
					var data;
					var tip=arrTitle[id-1];
					//
					switch(id){
					case 1:
						data = {data:{
								"type": id,
								"integralExchangeNum":$dialog_edit.find('#integralExchangeNum').val(),
								"integralExchangeEnable":$dialog_edit.find("input[name='integralExchangeEnable']:checked").val(),
								"integralGain1Enable":$dialog_edit.find("input[name='integralGain1Enable']:checked").val(),
								"integralGain1Num":$dialog_edit.find("#integralGain1Num").val(),
								"integralGain2Enable":$dialog_edit.find("input[name='integralGain2Enable']:checked").val(),
								"integralGain2Num":$dialog_edit.find("#integralGain2Num").val(),
								"integralGain3Enable":$dialog_edit.find("input[name='integralGain3Enable']:checked").val(),
								"integralGain3Num":$dialog_edit.find("#integralGain3Num").val(),
								"integralGain4Enable":$dialog_edit.find("input[name='integralGain4Enable']:checked").val(),
								"integralGain4Num":$dialog_edit.find("#integralGain4Num").val(),
								"integralGain5Enable":$dialog_edit.find("input[name='integralGain5Enable']:checked").val(),
								"integralGain5Num":$dialog_edit.find("#integralGain5Num").val(),
								"integralConsumptionEnable":$dialog_edit.find("input[name='integralConsumptionEnable']:checked").val(),
								"integralConsumption1Enable":$dialog_edit.find("input[name='integralConsumption1Enable']:checked").val(),
								"integralConsumption1num":$dialog_edit.find("#integralConsumption1num").val(),
								"integralConsumption2num":$dialog_edit.find("#integralConsumption2num").val()
							}
						};
						break;
					case 2:
						data = {
							"type": id
						};
						break;
					case 3:
						data = {
							"type": id,
						};
						break;
					case 4:
						data = {
							"type": id
						};
						break;
					case 5:
						data = {
							"type": id
						};
						break;
					}
					if(url!=''){
						Common.ajaxPostWantResult(url,data,tip,window);
					}
					//
					//
				}
			}, {
				html: "<i class='ace-icon fa fa-times'></i> 取消",
				"class": "btn btn-danger btn-minier",
				click: function() {
					$(this).dialog("close");
				}
			}]
		});
		$dialog_edit=$("#dialog-edit");
		radioShowHideDiv($dialog_edit,'integralGain1Enable');
		radioShowHideDiv($dialog_edit,'integralGain2Enable');
		radioShowHideDiv($dialog_edit,'integralGain3Enable');
		radioShowHideDiv($dialog_edit,'integralGain4Enable');
		radioShowHideDiv($dialog_edit,'integralGain5Enable');
		radioShowHideDiv($dialog_edit,'integralConsumptionEnable');
		
		
	});	
	
	
});